What Functional Programmers can Learn from the Visitor Pattern

نویسنده

  • Konstantin Läufer
چکیده

This paper explores the practical potential for enhancing code reuse in functional languages by leveraging techniques and experiences from object-oriented programming. Since data types in typed functional languages do not support adding new variants, programming techniques derived from the object-oriented Visitor pattern can be readily applied to recursive functions on trees in functional languages. Specifically, we demonstrate how to define recursive functions on trees in such a way that they can be extended without modification through an inheritance-like mechanism. Furthermore, we demonstrate how the extensions themselves can be made highly reusable through a mechanism akin to mixin-based inheritance, which allows an extension to be applied to any suitable recursive function. These mechanisms combine well with the usual higher-order approach to reuse in functional languages. Although general encodings of inheritance in functional languages are not novel, such encodings lead to a particularly simple and elegant presentation when limited to recursive functions on trees. Because of their simplicity, we believe that these techniques have the potential to enhance code reuse in the practice of functional programming without requiring additional tool support.

برای دانلود متن کامل این مقاله و بیش از 32 میلیون مقاله دیگر ابتدا ثبت نام کنید

ثبت نام

اگر عضو سایت هستید لطفا وارد حساب کاربری خود شوید

منابع مشابه

Adopting New International Health Instruments – What Can We Learn From the FCTC?; Comment on “The Legal Strength of International Health Instruments - What It Brings to Global Health Governance?”

This Commentary forms a response to Nikogosian’s and Kickbusch’s forward-looking perspective about the legal strength of international health instruments. Building on their arguments, in this commentary we consider what we can learn from the Framework Convention on Tobacco Control (FCTC) for the adoption of new legal international health instruments.

متن کامل

The Function, and Dysfunction, of Information Sources in Learning Functional Programming

Programmers experienced in using imperative languages can increasingly benefit from also knowing how to use functional languages. However, even if programmers have already mastered general programming constructs such as types and recursion, actually expressing these in a functional language can be challenging. In this paper, we present an observational study investigating what information sourc...

متن کامل

An Analysis of Visitor Circulation:

How visitors circulate through museums determines what they will see, where they will focus their attention, and, ultimately, what they will learn and experience. Unfortunately, the consistency of these movement patterns is not readily apparent. This article reviews the literature on visitor circulation in light of the general value principle which predicts choice behavior as a ratio of perceiv...

متن کامل

Functional Visitors Revisited

In object-oriented programming the visitor design pattern allows for the addition of new operations on a data hierarchy, but lends itself to scattered traversal code and makes visitors difficult to combine. Previous attempts to solve these issues have separated traversal code from the data structure but still face a lack of modularity in visitor computation making it difficult– if not impossibl...

متن کامل

How Can a Global Social Support System Hope to Achieve Fairer Competiveness?; Comment on “A Global Social Support System: What the International Community Could Learn From the United States’ National Basketball Association”

Ooms et al sets out some good general principles for a global social support system to improve fairer global competitiveness as a result of redistribution. This commentary sets out to summarize some of the conditions that would need to be satisfied for it to level up gradients in inequality through such a social support system, using the National Basketball Association (NBA) example as a point ...

متن کامل

ذخیره در منابع من


  با ذخیره ی این منبع در منابع من، دسترسی به آن را برای استفاده های بعدی آسان تر کنید

برای دانلود متن کامل این مقاله و بیش از 32 میلیون مقاله دیگر ابتدا ثبت نام کنید

ثبت نام

اگر عضو سایت هستید لطفا وارد حساب کاربری خود شوید

عنوان ژورنال:

دوره   شماره 

صفحات  -

تاریخ انتشار 2004